home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / serial / dim-1.000 / dim-1 / dim-1.03 / build next >
Text File  |  1994-01-26  |  5KB  |  168 lines

  1. #!./bin/icmake -qi
  2.  
  3. #define VER        "1.03"
  4.  
  5. /*
  6.         NOTE: This is an icmake-script.
  7.     
  8.         For your convenience, I have included de icmake binaries
  9.     in the dim-subdirectory, hence the line
  10.  
  11.                         #!./bin/icmake -qi
  12.  
  13.         icmake is not a part of dim, but it allows you to create dim from 
  14.     the sources. If you already have icmake, or if you want to have
  15.     icmake in another directory, the icm* files in the bin subdirectory
  16.     can be deleted or moved. If so, change the './bin/' path specification
  17.     in the first line of this file to the path where you keep icmake. 
  18.     E.g.,           #!/usr/local/bin/icmake -qi
  19.     
  20.     If you're interested in obtaining icmake: it's at
  21.             - tsx-11.mit.edu in the linux-subdirectory sources/usr.bin,
  22.         - sunsite.unc.edu in the linux-subdirectory devel,
  23.             - beatrix.icce.rug.nl in the directory /pub/unix
  24.         
  25.         NOTE that the icmake binaries in the bin subdirectory were
  26.     last compiled with the 4.5.8 shared libraries. Icmake will
  27.     complain about the version if you use an older one, but will
  28.     do its job normally.
  29. */    
  30.  
  31.  
  32.  
  33. /*      ----------------------------------------------------------
  34.         Programs used. If you don't have them in your path,
  35.     alter the program names such that they can be found
  36. */    
  37. #define AR        "ar"
  38. #define    ARREPLACE    "rvs"
  39. #define CC        "gcc"
  40. #define    CFLAGS    "-c -Wall"
  41. #define CHMOD           "chmod"
  42. #define CP              "cp"
  43. #define RM              "rm"
  44. #define STRIP        "strip"
  45.  
  46. /*      ---------------------------------------------------------
  47.         Paths used. If you don't want these, alter them
  48. */
  49.  
  50. #define CONFDIM         "/conf/dim"
  51. #define DIMDEST        "/usr/local/bin"
  52.  
  53.  
  54. //================================================================
  55. //      The remainder is the icmake-script, doing its thing.
  56. //      Don't alter what follows, unless you know what you're doing
  57.  
  58. int compdir ()
  59. {
  60.     int
  61.         ret,
  62.         i;
  63.     list
  64.         ofiles,
  65.         cfiles;
  66.     string
  67.         hfile,
  68.         cfile,
  69.         ofile,
  70.         libfile;
  71.  
  72.     libfile = "libdim.a";                       // set some filenames
  73.     hfile = "dim.h";
  74.     
  75.     chdir("src");                              // go to source-dir
  76.  
  77.     if (hfile younger libfile)                  // hfile changed: make all
  78.         cfiles = makelist ("*.c");
  79.     else                                        // recompile changed c-files.
  80.         cfiles = makelist ("*.c", younger, libfile);
  81.     
  82.     for (i = 0; i < sizeof (cfiles); i++)       // do the compilation
  83.     {
  84.         cfile = element (i, cfiles);
  85.         ofile = change_ext (cfile, ".o");
  86.         
  87.         if (cfile younger ofile)
  88.             exec (CC, CFLAGS, cfile);
  89.     }
  90.     
  91.     if (ofiles = makelist("*.o"))               // put .o files in the lib.
  92.     {
  93.         exec(AR, ARREPLACE, libfile, "*.o");
  94.         exec("rm", "*.o");
  95.         ret = 1;                                // relink required
  96.     }
  97.     
  98.     chdir("..");                                // back to org dir.
  99.     
  100.     ret |= "bin/dim" older "src/" + libfile;   // library ok, no prog yet
  101.  
  102.     return (ret);                               // if ret == 0, no relink
  103. }
  104.  
  105. void linkprog ()
  106. {
  107.     chdir ("src");
  108.     exec (CC, "-o", "../bin/dim", "-ldim", "-L.");
  109.     chdir ("..");
  110. }
  111.  
  112. void buildprog ()
  113. {
  114.     int
  115.         dim;
  116.         
  117.     if (compdir())
  118.         linkprog ();
  119.     printf("bin/dim is up-to-date\n");
  120. }
  121.  
  122. void instprog (string destdir)
  123. {
  124.     exec (STRIP, "bin/dim");
  125.     exec (CHMOD, "700", "bin/dim", CONFDIM);    // rwx for owner of dim
  126.                                                 // including getty-files dir.
  127.     exec (CP, "bin/dim", destdir);
  128. }
  129.  
  130. void install ()
  131. {
  132.     buildprog ();
  133.     instprog (DIMDEST);
  134.     printf
  135.     (
  136.         "Make sure getty.ttyS#.[org dis] are copied to ", CONFDIM, "\n"
  137.     "YOU HAVE TO DO THAT YOURSELF !\n"
  138.     );
  139. }
  140.  
  141. void clean ()
  142. {
  143.     chdir ("src");
  144.     exec ("rm", "-f", "*.o lib*.a");
  145.     chdir ("..");
  146.     exec ("rm", "-f", "build.bim");
  147. }
  148.  
  149. int main (int argc, list argv)
  150. {
  151.     if (element (1, argv) == "dim")             // build the programs
  152.         buildprog ();
  153.     else if (element (1, argv) == "install")
  154.         install ();                             // install the programs
  155.     else if (element (1, argv) == "clean")
  156.         clean ();                               // cleanup garbage
  157.     else
  158.     {
  159.         printf ("\n"
  160.             "Usage: build dim       - builds dim\n"
  161.               "       build install   - installs dim (if you're allowed to)\n"
  162.             "       build clean     - cleanup .o files etc.\n"
  163.             "\n");
  164.         return (1);
  165.     }
  166.     return (0);
  167. }
  168.